package com.example.basic;

/**
 * @author zhangs
 * @version v1.0
 * @decription Thread.join方法的使用
 * @date 2021/3/28 12:15
 **/
public class ThreadJoin {
    public static void main(String[] args) {
        final Thread threadA = new Thread(() -> {
            System.out.println("线程A开始执行");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程A执行完成");
        });

        final Thread threadB = new Thread(() -> {
            System.out.println("线程B正在执行，然后调用ThreadA的join()方法");
            try {
                threadA.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程B再次执行");
        });

        threadB.start();
        threadA.start();
    }
}
